<template>
    <div class="sys-page">
        <app-title title="系统会话时限管理"  style="display:inline;"></app-title>
        <el-button type="success" @click="refresh()" round style="float:right; margin-top:10px;" icon="el-icon-refresh">刷新</el-button>
        <!-- <app-notes>...</app-notes> -->

            <el-table v-loading="loading" border :data="tableData.body" :row-class-name="tableRowClassName">
                <el-table-column prop="content" label="有效期(分钟)" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="edit">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-dialog :title="dialogTitle" :visible.sync="editTableShow" width='50%' :fullscreen='false'>
                <el-select v-model="selectVal" placeholder="1">
                    <el-option
                    v-for="item in 10"
                    :key="item"
                    :label="item"
                    :value="item">
                    </el-option>
                </el-select>
                <el-button @click.native.prevent="ok">确定</el-button>
                <el-button @click.native.prevent="cancel">取消</el-button>

            </el-dialog>
    </div>

</template>
<style>
  .el-table .warning-row {
    background: #F08080;
  }

  .el-table .success-row {
    background:#f0f9eb;
  }
</style>
<script>
export default {
    name: 'sessiontimepolicy',
    inject: ['reload'],
    data(){
        return {
            dialogTitle:"系统会话时限管理(分钟)",
            failcnt:1,
            loading: false,
            editTableShow: false,
            selectVal:1,
            tableData:{
                body:[{content: 1}],
                head:[],
                loading:true
            },
            errorMsg:"您的信息有误，请联系管理员修改",
            issafe:true

       }
    },
    mounted(){
        this.query()
    },
    methods:{
        refresh(){
            this.query()
        },
        tableRowClassName({row, rowIndex}) {
          if(this.issafe === false){
            return 'warning-row';
          }else{
              return 'success-row'
          }
        },
        edit(){
            this.selectVal = this.tableData.body[0].content
            this.editTableShow = true
        },
        ok(){
            this.HTTP.methods.apiPost("/sysconfig/b0009.shtml",
                {content:this.selectVal}).then(res =>
            {
                if (res.code != 200) {
                this.$message(res.msg);
            } else {
                this.$message("配置成功");
                this.editTableShow = false;
                this.reload();
            }

        })


        },
        cancel(){
            this.editTableShow = false
            this.failcnt = 1
            this.selectVal = 1

        },
        //缺少一种点进去链接，就发请求的listener
        query(){
            this.HTTP.methods.apiGet("/sysconfig/b0009", {}).then(res =>
            {
                if(res.code == 200){
                this.tableData.body[0].content = (res.data.content)
                this.issafe = res.data.safe
            }else{
                this.tableData.body = []
            }
        })
        }
    }
}
</script>


